import { getToken } from '@/utils/auth'
import config from '@/config'
// const BASE_URL = 'http://123.56.40.213'
const BASE_URL = config.baseUrl
// const BASE_URL = 'http://192.168.0.143:8083' // 后端的主机名 + 端口号
// const BASE_URL = 'https://www.qdlyner.com/1001' // 后端的主机名 + 端口号
export const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		let token = getToken()
		// console.log(token+'123')
		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header:options.header || {
				// 根据实际接口设计 key 取 token 或者 authorization
				authorization: token,
				// authorization: "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjM1ZDM2ZDA3LTUzNzktNDMzZi05ZGM4LTU4ZTgxYjgyOGZmYiJ9.Ex_A7pyKlIbzA0zQflMTl9cV7o9jEIPCdyKKDsvmt5WjGtPORSQ7UzLKGK52rBsZxNFGh4l89xoCM29dnh_BpA"
			},
			
			success: (res) => {
				
				// console.log(res)
				if (res.data.code != 200) { // 这里根据后端的返回状态码来改
					return uni.showToast({
						title: '获取数据失败！',
						icon: 'fail'
					});
				}
				resolve(res);
			},
			fail: (err) => {
				uni.showToast({
					title: '请求接口失败',
					icon: 'fail'
				})
				reject(err)
			}
		})
	})
}
